package com.cat.dataStructure02;

import java.util.HashMap;
import java.util.List;

/**
*   @description https://leetcode.cn/problems/minimum-array-length-after-pair-removals/
*   @author 曲大人的喵
*   @create 2025/11/1 16:54
*   @since JDK17
*/

public class Solution92 {
    public int minLengthAfterRemovals(List<Integer> nums) {
        int n = nums.size(), max = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int x : nums) {    // 统计所有数字的最大数量
            map.merge(x, 1, Integer::sum);
            max = Math.max(max, map.get(x));
        }
        int rest = n - max;
        if (max > rest) {
            return max - rest;
        } else {
            return n % 2;
        }
    }
}
